package leetcodecompetition.D375;

import org.junit.jupiter.api.Test;

import java.sql.ClientInfoStatus;
import java.util.*;

/**
 * @Author: Siantar
 * @Date: 2023-12-10-11:25
 * @Description: 1.0
 */
public class T100136 {
    public int numberOfGoodPartitions(int[] nums) {
        int n = nums.length;
        int res = 0;
        int M = 1000_000_007;
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(nums[i], i);
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, map.get(nums[i]));
            if (max == i) {
                res++;
            }
        }
        System.out.println(res);
        return pow(2, res - 1, M);
    }

    public int pow(int a, int b, int m) {
        long mark = a, res = 1;
        while (b > 0) {
            if ((b & 1) == 1) {
                res = (res * mark) % m;
            }
            mark = (mark * mark) % m;
            b >>= 1;
        }
        return (int) res;
    }

    @Test
    public void test() {
        System.out.println(numberOfGoodPartitions(new int[]{1, 2, 1, 3}));
    }

}
